package ldkxingzhe.l365calendar.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * l365Calendar.db 's openHelper
 * Created by ke on 16-1-30.
 */
public class L365CalendarOpenHelper extends SQLiteOpenHelper{
    @SuppressWarnings("unused")
    private static final String TAG = "L365CalendarOpenHelper";

    public static final String DA_NAME = "l365Calendar";
    public static final int VERSION = 1;

    public static final String TABLE_NOTE = "note";

    public static final String NOTE_ID = "_id";
    public static final String NOTE_CREATED = "created";
    public static final String NOTE_MODIFIED = "modified";
    public static final String NOTE_TITLE = "title";
    public static final String NOTE_STATE = "state";
    public static final String NOTE_PRIORITY = "priority";
    public static final String NOTE_FINISH_TIME = "finish_time";
    public static final String NOTE_DEADLINE = "deadline";
    public static final String NOTE_TAG = "tags";
    public static final String NOTE_UUID = "uuid";
    private static final String CREATE_TABLE_NOTE =
            "CREATE TABLE IF NOT EXISTS " + TABLE_NOTE + "(" +
            NOTE_ID + " integer primary key autoincrement," +
            NOTE_CREATED + " integer not null," +
            NOTE_MODIFIED + " integer not null," +
            NOTE_TITLE + " text," +
            NOTE_STATE + " integer," +
            NOTE_PRIORITY + " integer," +
            NOTE_FINISH_TIME + " integer," +
            NOTE_DEADLINE + " integer," +
            NOTE_TAG + " text," +
            NOTE_UUID + " text" +
            ")";

    private static L365CalendarOpenHelper mInstance;
    synchronized public static L365CalendarOpenHelper getInstance(Context context){
        if(mInstance == null){
            mInstance = new L365CalendarOpenHelper(context);
        }
        return mInstance;
    }

    private L365CalendarOpenHelper(Context context) {
        super(context, DA_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_NOTE);
        Log.v(TAG, "onCreate, database was created");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF IT EXIST " + TABLE_NOTE);
        onCreate(db);
    }
}
